package controller;

import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import pojo.Category;
import pojo.Page;
import service.CatgoryService;
import javax.annotation.Resource;
import java.util.List;

/**
 * @ClassName 刘星宇
 * @Description TODO
 * @date 2022/11/25 15:10
 * @Version 1.0
 */
@RestController
public class CategoryController {
    @Resource
    private CatgoryService cargoryService;
    @RequestMapping("getCatAll")
    public List<Category> getCatAll(){
        List<Category> list = cargoryService.getCatAll();
        System.out.println(list);
        return list;
    }
    @RequestMapping("getCatAllByPage")
    public Page<Category> getCatAllByPage(int currentPage, int pageSize){
        Page<Category> CatPage = cargoryService.getCatAllByPage(new Page<Category>(currentPage,pageSize,0,null));
        return CatPage;
    }
    @RequestMapping("addCategory")
    public int addCategory(@RequestBody Category category){
        System.out.println(category);
        int i = cargoryService.addOrUpCategory(category);
        return i;
    }
    @RequestMapping("delCategory")
    public int delCategory(int categoryID){
        Category c = new Category();
        c.setCategoryID(categoryID);
        int i = cargoryService.getCatDel(c);
        return i;
    }
}
